import config from 'config'
import httpFetch from 'share/httpFetch'
import { message } from 'antd'

const orderCenterServer = (context) => {
  return {

    // 获取机票数据列表
    async getPlaneData(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post(`/vendor-data-service/api/order/air/order/query`,params);
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },

    // 获取机票数据详情
    async getPlaneDetail(params){
      try{
        context.setState({loading: true});
        const response = await httpFetch.post('/vendor-data-service/api/order/air/order/detail/query',params);
        return response;
      }catch (e) {
        dealWithErrorMes(e)
      }finally {
        context.setState({loading: false})
      }
    },

    // 导出数据
    async exportOrderCenterData(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post(`/vendor-data-service/api/order/air/order/export`, params);
        return response;
      }catch (e) {
        dealWithErrorMes(e)
      }finally {
        context.setState({loading: false})
      }
    },

  }
}

const dealWithErrorMes = (err) => {
  message.error(`error:${err.response.data.message}`);
}

export default orderCenterServer;
